package com.ruoyi.file.service;

import com.ruoyi.file.bean.FileUploadResult;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 文件上传接口。
 *
 * @author william.zhao and zhao xiang.
 * @version 1.0
 * @date 2023/05/05
 * @since jdk-17.0.2
 */
public interface ISysFileService {
    /**
     * 文件上传接口。
     *
     * @param file 上传的文件。
     * @return the upload result, result[0] means the url, result[1] means the file path.
     * @throws Exception
     */
    FileUploadResult uploadFile(MultipartFile file) throws Exception;

    /**
     * 文件上传接口。
     *
     * @param file 上传的文件。fileCode 适应老项目上传的fileCode
     * @return 访问地址。
     * @throws Exception
     */
    FileUploadResult uploadFileWithFileCode(String fileCode, MultipartFile file) throws Exception;

    /**
     * upload file by path.
     *
     * @param filePath
     * @param file
     * @return
     * @throws Exception
     */
    FileUploadResult uploadFileByPath(String filePath, MultipartFile file) throws Exception;

    /**
     * remove file by file path in server.
     *
     * @param filePath the file path in server.
     * @return success or fail.
     */
    String removeFile(String filePath);

    /**
     * upload file with file folder.
     *
     * @param folder the file folder.
     * @param file   the multipart file.
     * @return the file upload result.
     * @throws Exception if any exceptions happened throw them.
     */
    FileUploadResult uploadFileWithFileFolder(String folder, MultipartFile file) throws Exception;

    /**
     * preview.
     *
     * @param fileName the file name.
     * @param response response
     */
    void preview(String fileName, HttpServletResponse response);

    /**
     * get content by url.
     *
     * @param url       the file url.
     * @param extension the file extension.
     * @return the fine content.
     */
    String getContentByURL(String url, String extension);

    /**
     * get file list under special path.
     *
     * @param path the file path in server
     * @return the file path list under a special path.
     */
    List<String> getFileListUnberPath(String path);

    /**
     * get file inputstream by file path in server.
     *
     * @param filePath the file path in server.
     * @return the inputstream.
     */
    InputStream getInputStreamByPath(String filePath);
}
